@isTest
private class ContractProductHandlerTest {
    static testMethod void testMethod1() {


        Province__c pro = TestUtils.createProvince();
        insert pro;

        City__c c = TestUtils.createCity();
        c.Province__c = pro.Id;
        insert c;

        District__c d = TestUtils.createDistrict();
        d.City__c = c.Id;
        insert d;

        // 客户
        Account acc = new Account();
        acc.Name = 'test customer';
        acc.Status__c = '审核通过';
        acc.Level__c = '一级医院';
        acc.RecordTypeId = Utils.getRecordTypeIdByDevNameAndObjName('Dealer', 'Account');
        insert acc;



         //业务机会1
        Opportunity opp = TestUtils.createOpportunity();
        opp.AccountId = acc.Id;
        opp.RecordTypeId = Utils.getRecordTypeIdByDevNameAndObjName('DealerOpportunity', 'Opportunity');
        insert opp;


        Product__c p  = TestUtils.createInst();
        p.Name = '测试仪器';
        p.RecordTypeId = Utils.getRecordTypeIdByDevNameAndObjName('NCProduct', 'Product__c');
        p.Category0__c  = '仪器';
        p.Category1__c ='生化';
        p.ProductName__c = '测试仪器';
        //p.ProductStructure__c = ps1.Id;
      //  p.CRMBrand__c = brand.Id;
        p.NCCode__c = '10';
        p.InstrumentType__c = '维保仪器';
        insert p ;


         Contract__c con = new Contract__c();
        con.Account__c = acc.Id;
        con.Opportunity__c = opp.Id;
       	con.Status__c  = '已生效';
        con.Corpcode__c = 'MKSY';
        con.RecordTypeId = Utils.getRecordTypeIdByDevNameAndObjName('TerminalContract', 'Contract__c');
        insert con;



        ContractProduct__c cp = new ContractProduct__c();
        cp.Contract__c = con.Id;
        cp.Product__c =p.Id  ;
        cp.Quantity__c = 5;
        cp.OriginNumber__c = 5;
        cp.SalesPrice__c = 1; 
        cp.Opportunity__c = opp.Id;
       // cp.QuoteProduct__c = qp.Id;
        cp.CoopType__c = '正常销售';
        cp.ApplicationQuantity__c = 5;
        insert cp ;

        ContractReagentInformation__c cpr = new ContractReagentInformation__c();
        cpr.ReagentProducts__c =p.Id  ;
        cpr.Opportunity__c = opp.Id;
       // cp.QuoteProduct__c = qp.Id;
        cpr.Contract__c = con.Id;
        insert cpr ;

        cp.InstallQuantity__c = 5;
        try {
             update cp;
             ContractProductHandler.upgradeStage(new Set<Id>{con.Id});
        }
        catch (Exception e) {
            System.debug('ContractProductHandlerTest=>'+e.getMessage());
        }
        
       


        
    }

     static testMethod void testMethod2() {


        Province__c pro = TestUtils.createProvince();
        insert pro;

        City__c c = TestUtils.createCity();
        c.Province__c = pro.Id;
        insert c;

        District__c d = TestUtils.createDistrict();
        d.City__c = c.Id;
        insert d;

        // 客户
        Account acc = new Account();
        acc.Name = 'test customer';
        acc.Status__c = '审核通过';
        acc.Level__c = '一级医院';
        acc.RecordTypeId = Utils.getRecordTypeIdByDevNameAndObjName('TerminalCustomer', 'Account');
        acc.DeliveryControl__c = '按季管控';
        insert acc;



         //业务机会1
        Opportunity opp = TestUtils.createOpportunity();
        opp.AccountId = acc.Id;
        opp.RecordTypeId = Utils.getRecordTypeIdByDevNameAndObjName('CustomerOpportunity', 'Opportunity');
        insert opp;


        Product__c p  = TestUtils.createInst();
        p.Name = '测试仪器';
        p.RecordTypeId = Utils.getRecordTypeIdByDevNameAndObjName('NCProduct', 'Product__c');
        p.Category0__c  = '仪器';
        p.Category1__c ='生化';
        p.ProductName__c = '测试仪器';
        //p.ProductStructure__c = ps1.Id;
      //  p.CRMBrand__c = brand.Id;
        p.NCCode__c = '10';
        p.InstrumentType__c = '维保仪器';
        insert p ;


         Contract__c con = new Contract__c();
        con.Account__c = acc.Id;
        con.Opportunity__c = opp.Id;
        con.Status__c  = 'OA审批中';
        con.Corpcode__c = 'MKSY';
        con.RecordTypeId = Utils.getRecordTypeIdByDevNameAndObjName('TerminalContract', 'Contract__c');
        insert con;



        ContractProduct__c cp = new ContractProduct__c();
        cp.Contract__c = con.Id;
        cp.Product__c =p.Id  ;
        cp.Quantity__c = 5;
        cp.OriginNumber__c = 5;
        cp.SalesPrice__c = 1; 
        cp.Opportunity__c = opp.Id;
        cp.CoCustomer__c = acc.Id;
       // cp.QuoteProduct__c = qp.Id;
        cp.CoopType__c = '正常销售';
        cp.ApplicationQuantity__c = 5;
        insert cp ;




        
    }
}